package com.ruoyi.scheme.controller;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.scheme.dto.ErsSchemeCostBatchUpdateDTO;
import com.ruoyi.scheme.dto.ErsSchemeCostUploadDTO;
import com.ruoyi.scheme.service.ErsSchemeCostService;
import com.ruoyi.scheme.vo.ErsSchemeCostVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/ers/cost")
@DataSource(DataSourceType.SLAVE)
public class ErsSchemeCostController {

    private final ErsSchemeCostService ersSchemeCostService;

    /**
     * 批量上传对应一个生态修复方案的多个工程造价数据项
     *
     * @param ersSchemeCostUploadDTO
     * @return
     */
    @PostMapping
    public R<String> upload(@RequestBody @Valid List<@Valid ErsSchemeCostUploadDTO> ersSchemeCostUploadDTO) {

        ersSchemeCostService.upload(ersSchemeCostUploadDTO);
        return R.ok("添加成功");
    }

    /**
     * 批量修改一个生态修复方案的多个工程造价数据项
     * @param ersSchemeCostBatchUpdateDTO
     * @return
     */
    @PutMapping
    public R<String> update(@RequestBody @Valid ErsSchemeCostBatchUpdateDTO ersSchemeCostBatchUpdateDTO) {

        ersSchemeCostService.update(ersSchemeCostBatchUpdateDTO);
        return R.ok("修改成功");
    }

    /**
     * 查询一个生态修复方案的所有工程造价数据项
     * @param schemeId
     * @param schemeCostId
     * @return
     */
    @GetMapping
    public R<List<ErsSchemeCostVO>> get(@RequestParam(name = "schemeId", required = true) Long schemeId,
                                        @RequestParam(name = "schemeCostId", required = true) Integer schemeCostId) {

        return R.ok(ersSchemeCostService.get(schemeId, schemeCostId));
    }

    /**
     * 删除一个生态修复方案下所有工程造价数据项
     * @param schemeId
     * @return
     */
    @DeleteMapping("/{schemeId}")
    public R<String> delete(@PathVariable @NotNull(message = "生态修复方案ID不能为空") Long schemeId) {

        ersSchemeCostService.delete(schemeId);
        return R.ok("删除成功");
    }

}
